//
//  MainEnterViewController.m
//  TiscoNews
//
//  Created by love on 14-5-15.
//
//
#define WRITH  dispatch_queue_create("com.dispatch.writedb", DISPATCH_QUEUE_SERIAL)



#import "GTMNSString+HTML.h"
#import "XHAppDelegate.h"
#import "AFNetworking.h"
#import "AFHTTPRequestOperation.h"
#import "MJRefresh.h"
#import "UIImageView+AFNetworking.h"
#import "UIImageView+WebCache.h"
#import <MediaPlayer/MediaPlayer.h>
#import "XHURLString.h"
#import "NewsDetailViewController.h"


@interface customButton : UIButton


@end

@implementation customButton


-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.titleLabel.font = [UIFont systemFontOfSize:10];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
     
    }
    return  self;
}


-(CGRect)titleRectForContentRect:(CGRect)contentRect
{

    CGRect tempRect =  CGRectMake(5,11, self.frame.size.width-10, 12);
    return tempRect;
}

@end



#import "MainEnterViewController.h"
#import <QuartzCore/QuartzCore.h>


#define Column @[@"gongsixinwen",@"shipinxinwenv",@"taigangribao",@"meitikantaigang"]
#define Categroy @[@"news/article/articleinfo",@"news/article/video",@"news/article/articleinfo",@"news/article/articleinfo"]
#define ff 64
@interface MainEnterViewController ()
@end

@implementation MainEnterViewController



@synthesize allNewDic;
@synthesize buttonArray;
@synthesize tableArray;
@synthesize contentScrollView  = _contentScrollView;
@synthesize titleScrollView = _titleScrollView;
@synthesize titleArray;
@synthesize headerArray;
@synthesize footArrya;
@synthesize BseVIes = _BseVIes;
@synthesize yinitData;
@synthesize damokuai;
@synthesize lanmuTitles;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.titleArray = [NSMutableArray array];
        self.yinitData = [NSDictionary dictionary];
        self.urlstring = [[XHURLString alloc] init];
       
    }
    return self;
}
/*
-(NSString*)getAREACODe:(NSString*)address
{
    if([@"太原" isEqualToString:address]){
        return @"140100";
    }
    if([@"静乐" isEqualToString:address]){
        return @"035100";
    }
    if([@"大同" isEqualToString:address]){
        return @"037000";
    }
    if([@"阳泉" isEqualToString:address]){
        return @"045000";
    }
    if([@"长治" isEqualToString:address]){
        return @"046001";
    }
    if([@"晋城" isEqualToString:address]){
        return @"048000";
    }
    if([@"朔州" isEqualToString:address]){
        return @"036001";
    }
    if([@"晋中" isEqualToString:address]){
        return @"140700";
    }
    if([@"运城" isEqualToString:address]){
        return @"044000";
    }
    if([@"忻州" isEqualToString:address]){
        return @"034000";
    }
    if([@"临汾" isEqualToString:address]){
        return @"041000";
    }
    if([@"吕梁" isEqualToString:address]){
        return @"033000";
    }
    if([@"小店" isEqualToString:address]){
        return @"140105";
    }
    if([@"古交市" isEqualToString:address]){
        return @"030200";
    }
    if([@"万柏林" isEqualToString:address]){
        return @"030021";
    }
    if([@"晋源" isEqualToString:address]){
        return @"140110";
    }
    if([@"城区" isEqualToString:address]){
        return @"037001";
    }
    if([@"南郊区" isEqualToString:address]){
        return @"037002";
    }
    if([@"浑源" isEqualToString:address]){
        return @"037400";
    }
    if([@"灵丘" isEqualToString:address]){
        return @"034400";
    }
    if([@"阳泉城区" isEqualToString:address]){
        return @"045002";
    }
    if([@"阳泉矿区" isEqualToString:address]){
        return @"045003";
    }
    if([@"阳泉郊区" isEqualToString:address]){
        return @"045001";
    }
    if([@"盂县" isEqualToString:address]){
        return @"045100";
    }
    if([@"长治郊区" isEqualToString:address]){
        return @"046002";
    }
    if([@"襄垣" isEqualToString:address]){
        return @"046200";
    }
    if([@"屯留" isEqualToString:address]){
        return @"046100";
    }
    if([@"长子" isEqualToString:address]){
        return @"046600";
    }
    if([@"晋城城区" isEqualToString:address]){
        return @"048002";
    }
    if([@"沁水" isEqualToString:address]){
        return @"048200";
    }
    if([@"阳城" isEqualToString:address]){
        return @"048100";
    }
    if([@"泽州" isEqualToString:address]){
        return @"048001";
    }
    if([@"朔城区" isEqualToString:address]){
        return @"036002";
    }
    if([@"山阴" isEqualToString:address]){
        return @"036900";
    }
    if([@"怀仁" isEqualToString:address]){
        return @"038300";
    }
    if([@"和顺" isEqualToString:address]){
        return @"032700";
    }
    if([@"寿阳" isEqualToString:address]){
        return @"140725";
    }
    if([@"平遥" isEqualToString:address]){
        return @"031100";
    }
    if([@"灵石" isEqualToString:address]){
        return @"031301";
    }
    if([@"盐湖区" isEqualToString:address]){
        return @"044001";
    }
    if([@"永济" isEqualToString:address]){
        return @"044500";
    }
    if([@"河津" isEqualToString:address]){
        return @"043300";
    }
    if([@"忻府区" isEqualToString:address]){
        return @"034001";
    }
    if([@"定襄" isEqualToString:address]){
        return @"335400";
    }
    if([@"五台" isEqualToString:address]){
        return @"335500";
    }
    if([@"代县" isEqualToString:address]){
        return @"034200";
    }
    if([@"原平" isEqualToString:address]){
        return @"034100";
    }
    if([@"尧都区" isEqualToString:address]){
        return @"041002";
    }
    if([@"洪洞" isEqualToString:address]){
        return @"031600";
    }
    if([@"安泽" isEqualToString:address]){
        return @"042500";
    }
    if([@"离石区" isEqualToString:address]){
        return @"033099";
    }
    if([@"柳林" isEqualToString:address]){
        return @"033300";
    }
    if([@"交口" isEqualToString:address]){
        return @"032499";
    }
    if([@"孝义" isEqualToString:address]){
        return @"032300";
    }
    return @"140000";
    
}*/
-(void)addRIghtButton
{
   //self presentViewController:<#(UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>
}

-(void)back
{
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"modelNCOne" object:Nil];
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSString *)ggetNewsListWithAreaCode:(id)areaCode1 itemId:(id)itemId currentPage:(id)currentPage pageSize:(id)pageSize
{
    if ([damokuai isEqualToString:@"新闻动态"] ||[damokuai isEqualToString:@"便民信息"])
    {
        NSString* string = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/articles-list-%@-%@.html?pageNo=%@&pageSize=%@",itemId,areaCode1,currentPage,pageSize];
        return  string;
    }
    else if ([damokuai isEqualToString:@"舆情快报"])
    {
        NSString* UID = [[NSUserDefaults standardUserDefaults] objectForKey:@"UID"];
        if(UID)
        {
            NSString* string = [NSString stringWithFormat:@"http://183.203.18.45:7001/xinhua/m/articlelists-%@-%@-%@.html?pageNo=%@&pageSize=%@",UID,itemId,areaCode1,currentPage,pageSize];
            NSLog(@"舆情快报 = %@",string);
            return  string;
        }
    }
    return nil;
}

-(void)rightClick
{
    dishiViewController* viewController = [[dishiViewController alloc] init];
    viewController.block = ^(NSString* str,NSString*fff1)
    {
       // NSLog(fff1);
        
        lanmuTitles.text = str;
        if ([fff1 isEqualToString:areaCode])
        {
            NSLog(@"frff= %@",fff1);
            
        }
        
        else
        {
            NSLog(@"333 = %@",fff1);
            areaCode = fff1;
            [self reshrg];
            
        }
      
    };
    if ([_titleLable.text isEqualToString:@"地市热点"])
    {
        viewController.s1tring = @"只显示地市";
    }
   
    [self presentViewController:viewController animated:YES completion:nil];
}
-(void)reshrg //刷新
{
    [[AFHTTPRequestOperationManager manager].operationQueue cancelAllOperations];
    //self.allDIC = nil;
    [self.allNewDic removeAllObjects];
    // self.allDIC
    //[headerView beginRefreshing];
    for (int i = 0; i < [self.headerArray count]; i ++)
    {
        [[self.tableArray objectAtIndex:i] reloadData];
        dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_async(curQueue, ^{
            isRefresh = YES;
            [self loadNews:i page:@"0" pageSize:@"10"];
        });
        

    }
       NSLog(@"reshrg");
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    if ([self respondsToSelector:@selector(setTintColor:)])
    {
        [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    }
    
    self.view.backgroundColor = [UIColor whiteColor];
    CGFloat aY = kIOS_VERSION<7.0?0:20;
    
    _navBar = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0+aY)];
    _navBar.backgroundColor = [UIColor colorWithRed:2.0/255 green:102.0/255 blue:172.0/255 alpha:1.0];
    _navBar.userInteractionEnabled = YES;
    
    _titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, aY, self.view.frame.size.width, 44)];
    _titleLable.backgroundColor = [UIColor clearColor];
    _titleLable.text = [self.yinitData objectForKey:@"name"];
    _titleLable.textColor = [UIColor whiteColor];
    _titleLable.font = [UIFont systemFontOfSize:20];
    _titleLable.textAlignment = NSTextAlignmentCenter;
    [_navBar addSubview:_titleLable];
    [self.view addSubview:_navBar];
    lanmuTitles = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width-100, 5+aY, 60, 40)];
    lanmuTitles.backgroundColor = [UIColor clearColor];
    lanmuTitles.font = [UIFont systemFontOfSize:12];
    lanmuTitles.textColor = [UIColor whiteColor];
    [self.view addSubview:lanmuTitles];
    lanmuTitles.text =  COUTURYNAME;//COUTURYNAME;//复制时替换成 县区
    UIButton* _leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, aY, 40,40.0)];
    [_leftButton setImage:[UIImage imageNamed:@"icon_back@2x.png"] forState:UIControlStateNormal];
    _leftButton.imageEdgeInsets = UIEdgeInsetsMake(10, 13, 5, 5);
    [_leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_leftButton];
//file:///Users/love/Desktop/xinhua2.0/tab_spinner_normal.png
    
    if ([_titleLable.text isEqualToString:@"山西新闻"] )
    {
        areaCode = @"140000";
        lanmuTitles.hidden = YES;
    }
    
    else if ([_titleLable.text isEqualToString:@"地市热点"])
    {
        areaCode = CITYCODE;//复制时替换成 地市
        UIButton* _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-60, 5+aY, 40, 40)];
        [_rightButton setImage:[UIImage imageNamed:@"tab_spinner_normal.png"] forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_rightButton];
        lanmuTitles.text = CITYNAME;//复制时替换成 地市

    }
    else if ([_titleLable.text isEqualToString:@"县区快报"])
    {
        areaCode = COUTURYCODE;//复制时替换成 县区
        lanmuTitles.text = COUTURYNAME; //复制时替换成 县区
        UIButton* _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-60, 5+aY, 40, 40)];
        [_rightButton setImage:[UIImage imageNamed:@"tab_spinner_normal.png"] forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_rightButton];

    }
    else if ([_titleLable.text isEqualToString:@"便民信息"])
    {
         areaCode = COUTURYCODE;//复制时替换成 县区
        lanmuTitles.hidden = YES;
    }
    
    // Do any additional setup after loading the view, typically from a nib.
    if ([damokuai isEqualToString:@"舆情快报"] )
    {
        areaCode = COUTURYCODE;//复制时替换成 县区code
         lanmuTitles.hidden = YES;
    }
    self.allNewDic = [[NSMutableDictionary alloc] init];
    NSUserDefaults* dewq = [NSUserDefaults standardUserDefaults];
   // self.allNewDic = [dewq objectForKey:_titleLable.text];
    NSLog(@"lao     dfef");
    NSLog(@"%@",self.allNewDic);
    
       //   self.view.userInteractionEnabled=YES; //UIView是否接受并响应用户的交互
    // 58 133 201
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gmModelNoticicationCenterMethod:) name:@"modelNCOne" object:Nil];
    UIScrollView* titleScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0+ff, 320, 40)];
    //self.titleScrollView.backgroundColor = [UIColor blackColor];
    self.titleScrollView = titleScrollView;
    titleScrollView.showsHorizontalScrollIndicator = NO;
    [titleScrollView setBackgroundColor:[MainEnterViewController colorWithHexString:@"DFDFDF"]];
    titleScrollView.bounces = NO;
    //self.titleArray = [[NSMutableArray alloc] init];
    self.buttonArray = [[NSMutableArray alloc] init];
    _BseVIes = [[MJRefreshBaseView alloc] init];
  
   // self.titleArray = [NSMutableArray arrayWithObjects:@"公司新闻",@"视频新闻",@"太钢日报",@"媒体看太钢",nil];
    selectButton = 0;
    isRefresh  = YES;
    NSArray* ff1 = [self.yinitData objectForKey:@"childList"];
    for (int i = 0; i < [ff1 count]; i ++)
    {
        NSDictionary* dic = [ff1 objectAtIndex:i];
        [self.titleArray addObject:[dic objectForKey:@"name"]];
    }
    
    for (int i = 0; i < [self.titleArray count]; i++)
    {
        NSString* title = [self.titleArray objectAtIndex:i];
        NSInteger titleLeng = [title length];
        customButton* button = [[customButton alloc] initWithFrame:CGRectMake(self.ymNum+10, 0,titleLeng*18, 40)];
        [self.buttonArray addObject:button];
        [button setTag:10000+i];
        button.backgroundColor = [UIColor clearColor];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        if(i == 0)
        {
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.la = [[UIView alloc] initWithFrame:CGRectMake(self.ymNum, 1, titleLeng*18+20, 38)];
            self.la.backgroundColor = [UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f];
            [titleScrollView addSubview:self.la];
        }
        else
        {
              [button setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        }
        if (i < [self.titleArray count] -1)
        {
            UILabel* l = [[UILabel alloc] initWithFrame:CGRectMake(self.ymNum+20+titleLeng*18, 9, 1, 15)];
            l.backgroundColor = [UIColor grayColor];
            l.alpha = 0.2;
            [titleScrollView addSubview:l];
        }
        
        [button addTarget:self action:@selector(titleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        self.ymNum = self.ymNum + titleLeng*18 + 20;
        [button setTitle:title forState:UIControlStateNormal];
        
        
        [button.titleLabel setFont:[UIFont fontWithName:@"Arial" size:12.0f]];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
      
        [titleScrollView addSubview:button];
        
    }
    self.titleScrollView.contentSize = CGSizeMake(self.ymNum, 0);
    [self.view addSubview:titleScrollView];
    
    UIScrollView* contentScroView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30+ff, 320, self.view.frame.size.height-30-10)];
    contentScroView.delegate = self;
    self.contentScrollView = contentScroView;
    contentScroView.bounces = NO;
    contentScroView.showsHorizontalScrollIndicator = NO;
    contentScroView.showsVerticalScrollIndicator = NO;
    contentScroView.pagingEnabled = YES;
    contentScroView.contentSize = CGSizeMake([self.titleArray count] * 320, 0);
    [self.view addSubview:contentScroView];
    
    self.tableArray = [[NSMutableArray alloc] init];
    self.headerArray = [[NSMutableArray alloc] init];
    self.footArrya = [[NSMutableArray alloc] init];
    for (int i = 0; i < [self.titleArray count]; i++)
    {
        if ([damokuai isEqualToString:@"舆情快报"] && i == 2)
        {
            NSLog(@"da = %d",i);
            UIWebView* vw = [[UIWebView alloc] initWithFrame:CGRectMake(320*i, 0, 320, self.view.frame.size.height-80-10)];
            [self.contentScrollView addSubview:vw];
            [vw loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sx.xinhuanet.com/ztjn/2014zt/sjkfd/ss.html"]]];
            [[self.headerArray objectAtIndex:0] beginRefreshing];
            //self.tableArray addObject:vw];
            return;
        }
        UITableView* tableView = [[UITableView alloc] initWithFrame:CGRectMake(320*i, 0, 320, self.view.frame.size.height-80-10)];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tag = 20000 + i;
        //tableView.bounces = NO;;
        
        MJRefreshHeaderView* headerView = [MJRefreshHeaderView header];
        MJRefreshFooterView* footerView = [MJRefreshFooterView footer];
        headerView.delegate = self;
        footerView.delegate = self;
        headerView.tag = 30000+i;
        footerView.tag = 40000+i;
        
        headerView.scrollView = tableView;
        footerView.scrollView = tableView;
        NSDate * now = [NSDate date];
        NSDate * anHourAgo = [now dateByAddingTimeInterval:-60*5];
        [headerView setLastUpdateTime:anHourAgo];
        [self.headerArray addObject:headerView];
        [self.footArrya addObject:footerView];
        [self.tableArray addObject:tableView];
        [self.contentScrollView addSubview:tableView];
        [self setExtraCellLineHidden:tableView];
        //tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    }
    NSLog(@"init = %d",[self.tableArray count]);
    [[self.headerArray objectAtIndex:0] beginRefreshing];
    
}




-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
}

-(void)gmModelNoticicationCenterMethod:(id)sender{
    
    NSInteger theCategroy = [[[sender userInfo] objectForKey:@"theCategroy"] intValue];
    
    [self gmTransferDataToTableView:theCategroy];
    
    
    
    NSLog(@"使用其它线程对数据存档");
    //使用其它线程对数据存档
   
        dispatch_queue_t curQueueFour = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_async(curQueueFour, ^{
            NSLog(@"开始存档");
                          NSLog(@"缓存成功");
            
        });
    
    
    
}

-(void)gmTransferDataToTableView:(NSInteger)theCategory{
    
    dispatch_queue_t curQueueTwo = dispatch_get_main_queue();
    
    dispatch_async(curQueueTwo, ^{
        NSLog(@"222=  %d",theCategory);
        [[self.tableArray objectAtIndex:theCategory] reloadData];
        NSLog(@"%@reload 完成",[self.titleArray objectAtIndex:theCategory]);
        [[self.headerArray objectAtIndex:theCategory] endRefreshing];
        [[self.footArrya objectAtIndex:theCategory] endRefreshing];
    });
}

-(void)gmRequestNetData:(NSInteger)theModelid{
    
    dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(curQueue, ^{
        
        [self loadNews:theModelid page:@"0" pageSize:@"10"];
    });
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)loadNews:(NSInteger)i page:(NSString*)j pageSize:(NSString*)k
{
    NSNumber* newId;
    NSArray* ff1 = [self.yinitData objectForKey:@"childList"];
    //NSString* str = [self.urlstring getNewsListWithAreaCode:areaCode itemId: [[ff1 objectAtIndex:i] objectForKey:@"id"] currentPage:j pageSize:k];
    butoncl* bl = [[butoncl alloc] init];
    NSString* str1 = [NSString stringWithFormat:@"%@",[[ff1 objectAtIndex:i] objectForKey:@"id"]];
    NSLog(@"fff");
    [bl postString:@"001" fff:str1];
    NSString* str = [self ggetNewsListWithAreaCode:areaCode itemId:[[ff1 objectAtIndex:i] objectForKey:@"id"] currentPage:j pageSize:k];
    NSLog(@"rtl = %@",str);
    BOOL ishgg = isRefresh;
    //NSLog([@"%@ 开始加载数据   page =%@ ",[self.titleArray objectAtIndex:i],j);
    NSDictionary *tempCategory = [[NSDictionary alloc ] initWithObjectsAndKeys:[NSString stringWithFormat:@"%ld",(long)i],@"theCategroy", nil];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    if ([damokuai isEqualToString:@"舆情快报"])
    {
         //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    }
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation*operation, id responseObject) {
        ////NSLog([@"JSON: %@", responseObject);
        id jsonObject = [NSJSONSerialization JSONObjectWithData:operation.responseData
                                                        options:NSJSONReadingAllowFragments
                                                          error:nil];
        NSLog(@"json =- %@",jsonObject);
        // //NSLog([@"COUNT = %lu",(unsigned long)[jsonObject count]);
        NSArray* array = [jsonObject objectForKey:@"content"];
        NSLog(@"array = %d",[array count]);
        dispatch_async(WRITH, ^{
            if (ishgg)
            {
                //NSLog([@" %@写入 page = %@ 刷新",[self.titleArray objectAtIndex:i],j);
                ////NSLog([@"%@ is ",[self.titleArray objectAtIndex:i]);
              
                 NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:array,@"content",[jsonObject objectForKey:@"last"],@"last",[jsonObject objectForKey:@"currentPage"],@"currentPage", nil];
                [self.allNewDic removeObjectForKey:[self.titleArray objectAtIndex:i]];
                [self.allNewDic setObject:jsonObject forKey:[self.titleArray objectAtIndex:i]];
            
            }
            else{
                //NSLog([@" %@写入 更多",[self.titleArray objectAtIndex:i]);
              
                
                NSMutableArray* oldContentArray = [[NSMutableArray alloc] init];
                [oldContentArray addObjectsFromArray:[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"]];
                [oldContentArray addObjectsFromArray:array];
                
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:oldContentArray,@"content",[jsonObject objectForKey:@"last"],@"last",[jsonObject objectForKey:@"currentPage"],@"currentPage", nil];
            
                [self.allNewDic removeObjectForKey:[self.titleArray objectAtIndex:i]];
                [self.allNewDic setObject:dic forKey:[self.titleArray objectAtIndex:i]];

                
            }
            //[self performSelector:@selector(doneWithView:) withObject:_BseVIes afterDelay:0.0];
            //NSLog([@" %@写入 page = %@ 完成",[self.titleArray objectAtIndex:i],j);
            NSNotification *endData = [NSNotification notificationWithName:@"modelNCOne" object:nil userInfo:tempCategory];
            [[NSNotificationCenter defaultCenter] postNotification:endData];
            
        });
        //[self performSelector:@selector(fff:) withObject:i afterDelay:2.0];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError*error) {
        NSLog(@"Error: %@", error);
    
        [[self.headerArray objectAtIndex:i]  endRefreshing];
        [[self.footArrya objectAtIndex:i] endRefreshing];
    }];
    
    
    
    
    
    
    
}

-(void)fff:(NSInteger)i
{
    
    //NSLog([@"reloadData");
    [[self.tableArray objectAtIndex:i] reloadData];
    [[self.tableArray objectAtIndex:i] reloadSectionIndexTitles];
    [[self.headerArray objectAtIndex:i]  endRefreshing];
    [[self.footArrya objectAtIndex:i] endRefreshing];
    
    
}
- (void)setExtraCellLineHidden: (UITableView *)tableView{
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger j = 0;
    for (int i= 0; i < [self.titleArray count]; i ++)
    {
        if (tableView.tag == 20000+ i)
        {
            NSLog(@"fff");
            NSArray* ara = [self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]];
            NSLog(@"ara = %d",[ara count]);
            j =[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] count];
           
            NSLog(@"%@ 总共 %d行",[self.titleArray objectAtIndex:i],j);
            if(j == 0)
            {
                tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
            }
            else
            {
                 tableView.separatorStyle =  UITableViewCellSeparatorStyleSingleLine;
            }
            
        }
    }
    self.endtabCell = j;
    return j;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    customTablViewCell1* cell = [tableView dequeueReusableCellWithIdentifier:@"1"];
    
    if (cell == nil)
    {
        cell = [[customTablViewCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"1"];
    }
    
    for(int i = 0;i < [self.titleArray count];i ++)
    {
        if( tableView.tag == 20000 + i)
        {
            [cell setDic:[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]]  objectForKey:@"content"]objectAtIndex:indexPath.row] tag:tableView.tag];
            //NSString* title = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"artTitle"];
          
        }
        
    }
    //tableView.separatorStyle = UITableViewCellSelectionStyleGray;
    return cell;
}
-(NSString *)filterHTML:(NSString *)html
{
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text = nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<" intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">" intoString:&text];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
    }
    //    NSString * regEx = @"<([^>]*)>";
    //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
    return html;
}
- (UIImage *)capture
{
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return img;
}
+ (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    for(int i = 0;i < [self.titleArray count];i ++){
        if(tableView.tag == 20000+i){
            NSString* sting = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"link"];
            if([sting length] > 0)
            {
                
                NSString* s = [NSString stringWithFormat:@"http://183.203.18.45:7001%@",sting];
                MPMoviePlayerViewController *playerViewController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:s]];
                NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
                [notificationCenter addObserver:self
                                       selector:@selector(moviePlayerPreloadDidFinish:)
                                           name:
                 MPMediaPlaybackIsPreparedToPlayDidChangeNotification
                                         object:playerViewController];
                [playerViewController.moviePlayer play];
                [self presentMoviePlayerViewControllerAnimated:playerViewController];
            }
            else
            {
                NSNumber* newsId = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"id"];
                NSString* imageString = [[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] objectAtIndex:indexPath.row] objectForKey:@"iamge"];
                   NewsDetailViewController *newsDetailViewController = [[NewsDetailViewController alloc] initWithNewsId:newsId];
                if ([imageString length] > 0 && ![imageString isEqualToString:@"null"])
                {
                    if([imageString hasPrefix:@"http"])
                    {
                        
                        newsDetailViewController.imageString =  [NSString stringWithFormat:@"%@",imageString];
                        
                        
                    }
                    else
                    {
                        newsDetailViewController.imageString = [NSString stringWithFormat:@"http://183.203.18.45:7001%@",imageString];
                        
                    }
                    
                }
                NSLog(@"imagest = %@",newsDetailViewController.imageString);

                newsDetailViewController.fefncode = areaCode;
                [self.navigationController pushViewController:newsDetailViewController animated:YES];
            }
        }
    }
}
-(void)moviePlayerPreloadDidFinish:(id)sender

{
    
}
-(void)titleButtonAction:(UIButton *)button
{
    
    if (button.tag- 10000 == selectButton)
    {
        return;
    }
    
    //[[self.headerArray objectAtIndex:selectButton] endRefreshing];
    //[[self.footArrya objectAtIndex:selectButton] endRefreshing];
    [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //[[self.buttonArray objectAtIndex:selectButton] setBackgroundColor:[UIColor whiteColor]];
    [button setBackgroundColor:[UIColor clearColor]];
    selectButton = button.tag - 10000;
    
    [self.contentScrollView setContentOffset:CGPointMake(320*selectButton, 0) ];
    NSLog(@"1");
    id lastdata;
    if ([damokuai isEqualToString:@"舆情快报"] && selectButton == 2)
    {
        
    }
    else
    {
         lastdata = [[self.headerArray objectAtIndex:selectButton] lastUpdateTime] ;
    }

    NSTimeInterval item = [lastdata timeIntervalSinceNow];
    NSLog(@"2");
    if(abs(item) > 300          )
    {
        //[[self.headerArray objectAtIndex:selectButton] beginRefreshing];
        //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        //dispatch_async(curQueue, ^{
        //[self gmRequestNewsData:button.tag-10000];
        if ([damokuai isEqualToString:@"舆情快报"] && selectButton== 2)
        {
            
        }
        else
        {
            [[self.headerArray objectAtIndex:selectButton] beginRefreshing];
        }
        NSLog(@"3");
        //});
    }
    if (selectButton == 0)
    {
        [UIView animateWithDuration:0.2 animations:^{
          //  [self.titleScrollView setContentOffset:CGPointMake(0, 0)];
            
        }];

    }
    else if (selectButton == [self.tableArray count] -1)
    {
        NSLog(@"frame = %f %f  %f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x);
        [UIView animateWithDuration:0.2 animations:^{
          //  [self.titleScrollView setContentOffset:CGPointMake(button.frame.size.width-320+button.frame.origin.x, 0)];
            
        }];
    }
    else
    {
         NSLog(@"frame = %f %f  %f,%f  %f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x,self.titleScrollView.contentOffset.x);
    }
    if(button.center.x > 100 && button.center.x < self.ymNum-90){
        
    }
    [UIView animateWithDuration:0.2 animations:^{
        self.la.frame = CGRectMake(button.frame.origin.x-10, 1, button.frame.size.width+20, 38);
        
        
    }];
   

    
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    //  self.stratDragPoint = scrollView.contentOffset;//开始点
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    self.EndDragPoint = scrollView.contentOffset;//结束点
    
    
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    CGPoint tempPoint = scrollView.contentOffset;
    NSInteger tempSelect = tempPoint.x/320;
    
    ////NSLog([@"%ld = %ld",(long)selectButton, (long)tempSelect);
    if (self.EndDragPoint.y == 0 && (tempSelect != selectButton))
    {
        
        [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor colorWithRed:58.0f/255.0f green:133.0f/255.0f blue:201.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        selectButton = tempSelect;
        [[self.buttonArray objectAtIndex:selectButton] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        id lastdata;
        if([damokuai isEqualToString:@"舆情快报"] && selectButton == 2)
        {
        }
        else
        {
            lastdata = [[self.headerArray objectAtIndex:selectButton] lastUpdateTime] ;
        }
       
        // //NSLog([@"lastdata=%@",[lastdata class]);
        NSTimeInterval item = [lastdata timeIntervalSinceNow];
        if(abs(item) > 300          )
        {
            //[[self.headerArray objectAtIndex:selectButton] beginRefreshing];
            // dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
            // dispatch_async(curQueue, ^{
            //跟新数据，要去数据请求
            // [self gmRequestNewsData:selectButton+10000];
            if([damokuai isEqualToString:@"舆情快报"] && selectButton == 2)
            {
            }
            else
            {
                [[self.headerArray objectAtIndex:selectButton] beginRefreshing];

            }
            
                       // });
        }
        UIButton* button = [self.buttonArray objectAtIndex:selectButton];
        if (selectButton == 0)
        {
            [UIView animateWithDuration:0.2 animations:^{
               // [self.titleScrollView setContentOffset:CGPointMake(0, 0)];
                
            }];
            
        }
        else if (selectButton == [self.tableArray count] -1)
        {
            NSLog(@"frame = %f %f  %f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x);
            [UIView animateWithDuration:0.2 animations:^{
               // [self.titleScrollView setContentOffset:CGPointMake(button.frame.size.width-320+button.frame.origin.x, 0)];
                
            }];
        }
        else
        {
            NSLog(@"frame = %f %f  %f,%f  %f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.center.x,self.titleScrollView.contentOffset.x);
        }
        if(button.center.x > 100 && button.center.x < self.ymNum-90){
            
        }
        [UIView animateWithDuration:0.2 animations:^{
            self.la.frame = CGRectMake(button.frame.origin.x-10, 1, button.frame.size.width+20, 38);
            
            
        }];
        
    }
    
    
    
}



#pragma mark - 刷新控件的代理方法
#pragma mark 开始进入刷新状态
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    // //NSLog(@%@----开始进入刷新状态, refreshView.class);
    // 2.2秒后刷新表格UI
    //[self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:2.0];
    //NSLog([@"retag =%d",refreshView.tag);
    if ([refreshView.class isSubclassOfClass:[MJRefreshHeaderView class]])
    {
        for (int i=0; i < [self.headerArray count]; i++)
        {
            if (refreshView.tag == 30000+i)
            {
                isRefresh = YES;
                _BseVIes = nil;
                _BseVIes = refreshView;
                if ([damokuai isEqualToString:@"舆情快报"] && i == 2)
                {
                    [refreshView endRefreshing];
                    return;
                }
                [self gmRequestNetData:i];
            }
        }
    }
    else if ([refreshView.class isSubclassOfClass:[MJRefreshFooterView class]])
    {
        for (int i = 0; i < [self.footArrya count]; i ++)
        {
            if (refreshView.tag == 40000+ i)
            {
                
                isRefresh = NO;
                _BseVIes = nil;
                _BseVIes = refreshView;
                if ([damokuai isEqualToString:@"舆情快报"] && i == 2)
                {
                    [refreshView endRefreshing];
                    return;
                }
              
                NSString* countPage =  [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"last"];
                NSUInteger couf =  [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectForKey:@"content"] count];
                NSLog(@" a = %d, b= %u",couf/10, [countPage intValue]);
               if (couf%10 != 0)
               {
                   [refreshView endRefreshing];
                   return;
               }
                if ( couf/10 >= [countPage intValue] )
                {
                    [refreshView endRefreshing];
                    return;
                }
              
                NSString* st = [NSString stringWithFormat:@"%d",couf/10 +1] ;
                
                dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
                dispatch_async(curQueue, ^{
                    
                    [self loadNews:i page:st pageSize:@"10"];
                });
                
            }
        }
    }
    /*
     if ([self.headerArray objectAtIndex:selectButton] == refreshView)
     {
     isRefresh = YES;
     _BseVIes = nil;
     _BseVIes = refreshView;
     //NSNumber* i = [[_array objectAtIndex:selectButton] objectForKey:@"id"];
     int i = self.contentScrollView.contentOffset.x/320;
     
     //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
     //dispatch_async(curQueue, ^{
     [self gmRequestNetData:i];
     // [self loadNews:i page:@"1" pageSize:@"10"];
     // });
     }
     else
     {
     NSNumber* lastPage =  [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"lastPage"];
     if ([lastPage isEqualToNumber:@1])
     {
     [refreshView endRefreshing];
     return;
     }
     ////NSLog([@"sf==%d ",[[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] /10);
     if ([[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] /10 ==0 || [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"content"] count] %10 != 0)
     {
     
     
     [refreshView endRefreshing];
     return;
     }
     isRefresh = NO;
     _BseVIes = nil;
     _BseVIes = refreshView;
     NSNumber* next = [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"next"];
     NSNumber* last = [[self.allNewDic objectForKey:[self.titleArray objectAtIndex:selectButton]] objectForKey:@"last"];
     
     
     if (next <= last )
     {
     int i = self.contentScrollView.contentOffset.x/320;
     // NSNumber* i = [[_array objectAtIndex:selectButton] objectForKey:@"id"];
     NSString* st = [next stringValue];
     //dispatch_queue_t curQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
     // dispatch_async(curQueue, ^{
     [self gmRequestNetData:i];
     //[self loadNews:i page:st pageSize:@"10"];
     //});
     
     }
     
     
     }*/
    
}



#pragma mark 刷新完毕
- (void)refreshViewEndRefreshing:(MJRefreshBaseView *)refreshView
{
    ////NSLog(@%@----刷新完毕, refreshView.class);
}

#pragma mark 监听刷新状态的改变
- (void)refreshView:(MJRefreshBaseView *)refreshView stateChange:(MJRefreshState)state
{
    switch (state) {
        case MJRefreshStateNormal:
            // //NSLog(@%@----切换到：普通状态, refreshView.class);
            break;
            
        case MJRefreshStatePulling:
            // //NSLog(@%@----切换到：松开即可刷新的状态, refreshView.class);
            break;
            
        case MJRefreshStateRefreshing:
            // //NSLog(@%@----切换到：正在刷新状态, refreshView.class);
            break;
        default:
            break;
    }
}

#pragma mark 刷新表格并且结束正在刷新状态
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    // 刷新表格
    //[myTableView reloadData];
    
    // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
    _BseVIes = nil;
    [[self.tableArray objectAtIndex:selectButton] reloadData];
    [refreshView endRefreshing];
}

-(void)dealloc
{
    NSLog(@"dealloc1");
    
    for (int i = 0; i < [self.headerArray count]; i++)
    {
        [[self.headerArray objectAtIndex:i] free];
    }
    for (int i = 0; i < [self.footArrya count]; i++)
    {
        [[self.footArrya objectAtIndex:i] free];
    }
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"modelNCOne" object:Nil];
   
    self.tableArray = nil;
    self.contentScrollView = nil;
    self.titleArray = nil;
    self.allNewDic = nil;
  
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    //清除缓存：
    [[SDImageCache sharedImageCache] clearDisk];
    
    [[SDImageCache sharedImageCache] clearMemory];
    // Dis

#pragma mark - 刷新控件的代理方法
#pragma mark 开始进入刷新状态
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


@implementation customTablViewCell1;
@synthesize titleLable;
@synthesize chakanLable;
@synthesize imageView1;
@synthesize deLable;
@synthesize textView;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(5, 2+5, 300, 18)];
        self.titleLable.font = [UIFont systemFontOfSize:15];
        self.titleLable.textColor = [UIColor blackColor];
        self.titleLable.textAlignment = NSTextAlignmentLeft;
        self.titleLable.backgroundColor = [UIColor clearColor];
        [self addSubview:self.titleLable];
        
        self.deLable = [[UILabel alloc] initWithFrame:CGRectMake(70, 18+15, 240, 42)];
        self.deLable.font = [UIFont systemFontOfSize:11];
        self.deLable.textColor = [UIColor grayColor];
        self.deLable.textAlignment = NSTextAlignmentLeft;
        self.deLable.numberOfLines = 3;
        self.deLable.backgroundColor = [UIColor clearColor];
        [self addSubview:self.deLable];
        
        self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(8, 20+15, 55, 50)];
        imageView1.contentMode = UIViewContentModeScaleToFill;
       // imageView1.backgroundColor = [UIColor grayColor];
        imageView1.image = [UIImage imageNamed:@"base_list_default_icon.png"];
        [self addSubview:imageView1];
        
        
        
        self.chakanLable = [[UILabel alloc] initWithFrame:CGRectMake(260,60+15 , 40, 10)];
        self.chakanLable.font = [UIFont systemFontOfSize:8];
        self.chakanLable.textColor = [UIColor grayColor];
        self.chakanLable.textAlignment = NSTextAlignmentLeft;
        self.chakanLable.backgroundColor = [UIColor clearColor];
        self.chakanLable.text = @"0";
        [self addSubview:chakanLable];
        UIImageView* imagevs = [[UIImageView alloc] initWithFrame:CGRectMake(245, 60+15, 10, 10)];
        imagevs.contentMode = UIViewContentModeScaleToFill;
        imagevs.backgroundColor = [UIColor clearColor];
        imagevs.image = [UIImage imageNamed:@"news_listview_item_attention.png"];
        [self addSubview:imagevs];
        
        
    }
    return self;
}


-(void)setDic:(NSDictionary*)dic tag:(NSInteger)tag
{
    NSString* title = [dic objectForKey:@"title"];
    //title = [self filterHTML:title];
    title = [title gtm_stringByUnescapingFromHTML];
    self.titleLable.text = title;
    NSString* det = [dic  objectForKey:@"description"];
   
    det = [self filterHTML:det];
    det = [det gtm_stringByUnescapingFromHTML];
       
    self.deLable.text =  det;

   
    
    NSString* string  = [dic  objectForKey:@"image"];
    NSLog(@"photo = %@",string);
    if ([string length] > 0 && ![string isEqualToString:@"null"])
    {
        if([string hasPrefix:@"http"])
        {
            
            NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",string]];
            NSLog(@"url = %@",url);
            [self.imageView1 setImageWithURL:url placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",title]]];
        }
        else
        {
            NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://183.203.18.45:7001%@",string]];
            [self.imageView1 setImageWithURL:url placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",title]]];
        }
        
    }
    /* NSString* neid = [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectAtIndex:indexPath.row]  objectForKey:@"id"];
     NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.tisco.com.cn%@",string]];
     [cell.imageView1 setImageWithURL:url placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png",neid]]];
     NSNumber* hits = [NSNumber numberWithInt:0];
     NSString* f = [[[self.allNewDic objectForKey:[self.titleArray objectAtIndex:i]] objectAtIndex:indexPath.row]  objectForKey:@"agencyId"];
     ////NSLog([@"hits leng= %d",[hits intValue]);
     //NSString* f =[NSString stringWithFormat:@"%d",[hits intValue]];
     cell.chakanLable.text = f;*/
    id hits = [dic objectForKey:@"hits"];

   
    NSString* string22 = [NSString stringWithFormat:@"%@",hits];
    //NSLog([@"stt = %@,value = %d",string22,[string22 length]);
    if (![string22 isEqualToString:@"(null)"])
    {
        self.chakanLable.text = string22;
    }
}
-(NSString *)filterHTML:(NSString *)html
{
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text = nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<" intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">" intoString:&text];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
    }
    //    NSString * regEx = @"<([^>]*)>";
    //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
    return html;
}
-(void)dealloc
{
    NSLog(@"dealloc");
    
}
@end
